package  
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.LoaderInfo;
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author lee
	 */
	public class Helper
	{
		public static const inplayer:Boolean=true;
		private static var loaderInfo:LoaderInfo;
		private static var _params:Object = { };
		public function Helper(target:DisplayObject,msg:String="") 
		{
			loaderInfo = target.loaderInfo;
			if (msg != "") {
				loaderInfo.sharedEvents.dispatchEvent(new DataEvent(DataEvent.DATA, false, false, msg));
			}else {
				_params = loaderInfo.parameters;
				if (!inplayer) {
					if (target.stage != null) {
						removeAll(target.stage);
					}else {
						target.addEventListener(Event.ADDED_TO_STAGE, target_addedToStage);
					}
				}
			}
		}
		
		private function target_addedToStage(e:Event):void 
		{
			var target:DisplayObject = e.target as DisplayObject;
			if (target) {
				target.removeEventListener(Event.ADDED_TO_STAGE, target_addedToStage);
				if (target.stage) {
					removeAll(target.stage);
				}
			}
		}
		public static function getParam(name:String):String {
			if (_params[name] == undefined) {
				return "";
			}
			return _params[name];
		}
		private static function removeAll(target:DisplayObjectContainer):void {
			if (target != null) {
				var len:int = target.numChildren;
				while (len-- > 0) {
					target.removeChildAt(len);
				}
			}
		}
	}

}